let kinolar = [];
let nowattiki_kino_id = 0;

function izdax() {

}

//ساقلاش
function saklax() {
    let ismim = document.getElementById("#name");
    let rasmi = document.getElementById("#image");
    let turi = document.getElementById("#turi");
    if (ismim.value === "") {
        alert(' كىنو ئىسمىنى كىرگۈزۈپ بەسلە');
        return;
    }
    if (rasmi.value === "") {
        alert('كىنو رەسىمىنى كىرگۈزۈپ بەسلە');
        return;
    }
    if (nowattiki_kino_id > 0) {
        let index = kinolar.findIndex(kino => kino.id === nowattiki_kino_id);
        kinolar[index].isim = ismim.value;
        kinolar[index].rasmi = rasmi.value;
        kinolar[index].bahasi = turi.value;
        nowattiki_kino_id = 0;
    } else {
        kinolar.push({
            isim: ismim.value,
            turi: turi.value,
            id: kinolar.length + 1,
            rasmi: rasmi.value
        });
    }
    yiglash();
    ismim.value = "";
    rasmi.value = "";
    turi.value = "";
    alert('ساقلاندى');
}

// كىنو ئۇچۇرىنى ئۆزگەرتىش
function update(id) {
    nowattiki_kino_id = id;
    let index = kinolar.findIndex(kino => kino.id === id);
    let kino = kinolar[index];
    let ismim = document.getElementById("#name");
    let rasmi = document.getElementById("#image");
    let turi = document.getElementById("#turi");
    ismim.value = kino.isim;
    rasmi.value = kino.rasmi;
    turi.value = kino.turi;
}

// كىنونى ئۆچۈرۈش
function deletekino(id) {
    let index = kinolar.findIndex(kino => kino.id === id);
    kinolar.splice(index, 1);
    yiglash();
}

//كۆرۈنمە يۈزدىكى تىزىملىكنى يىڭىلاش
function yiglash() {
    let tizimlik = document.getElementById("#tizimlik");
    let tizimlik_html = "";
    kinolar.forEach(kino => {
        tizimlik_html += `<div class="column width-296px height-172px bg-gray1 margin-8px radius-all-8px row overflow-hidden">
            <div class="row">
                <img class="margin-8px radius-all-8px width-96px height-96px" src="http://mmbiz.qpic.cn/mmbiz_jpg/Xyj7chDIWOPmpeeicfVuhHJwk1fV5Vicse1JNUUXicWcvOAIEZhRzTaibQOU7j3O4ExiccTe1ibg7uNU54LFBYep9vnw/0">
                    <div class="space-full column">
                        <div class="height-32px vertical-center ltr margin-lr-8px">ID:${kino.id}</div>
                        <div class="height-32px vertical-center">ئىسمى:${kino.isim}</div>
                        <div class="height-32px vertical-center">تۈرى:${kino.turi}</div>
                    </div>
            </div>
            <div class="space-full row">
                <div class="space-full txt-center center bg-blue3"onclick="update(${kino.id})">ئۆزگەرتىش</div>
                <div class="space-full txt-center center bg-green9" onclick="deletekino(${kino.id})">ئۆچۈرۈش</div>
            </div>
        </div>`
    });
    tizimlik.innerHTML = tizimlik_html;
}
